package self.hoy.demo.cloud.conf;

import org.springframework.context.annotation.Bean;
import self.hoy.demo.cloud.MyTestContextFactory;
import self.hoy.demo.cloud.TestSpecification;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 三共小不
 * @date 2021/7/5
 */
public class AbcConfiguration {
    /**
     * 先定义一个ContextFactory对象,通过TestSpecification定义不同命名的
     * 子context需要加载的configuration，当命名是以default开头的，所有的
     *  子context共用该TestSpecification定义的configuration。
     */
    @Bean
    public MyTestContextFactory getMyTestContextFactory(){
        MyTestContextFactory context = new MyTestContextFactory();
        TestSpecification spcification = new TestSpecification("test0", new Class[]{TestContextAutoConfiguration.class/*, CommonContextAutoConfiguration.class*/});
        TestSpecification spcification1 = new TestSpecification("test1", new Class[]{Test1ContextAutoConfiguration.class/*, CommonContextAutoConfiguration.class*/});
        TestSpecification spcification2 = new TestSpecification("default.common", new Class[]{CommonContextAutoConfiguration.class});
        List<TestSpecification> spe = new ArrayList<>();
        spe.add(spcification);
        spe.add(spcification1);
        spe.add(spcification2);
        context.setConfigurations(spe);
        return context;
    }
}
